<template>
  <transition name="fade">
    <div class="message-dialog-overlay" v-if="visible" @click="closeOnMaskClick ? close() : null">
      <div class="message-dialog" :class="type">
        <div class="message-dialog-icon">
          <i v-if="type === 'success'" class="icon-success">✓</i>
          <i v-else-if="type === 'error'" class="icon-error">✕</i>
          <i v-else class="icon-info">i</i>
        </div>
        <div class="message-dialog-content">
          <h3 class="message-dialog-title">{{ title }}</h3>
          <p class="message-dialog-message">{{ message }}</p>
        </div>
        <div class="message-dialog-actions">
          <button class="message-dialog-btn" @click="close">{{ buttonText }}</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'MessageDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '提示'
    },
    message: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'info',
      validator: value => ['success', 'error', 'info'].includes(value)
    },
    buttonText: {
      type: String,
      default: '确定'
    },
    closeOnMaskClick: {
      type: Boolean,
      default: true
    },
    onClose: {
      type: Function,
      default: () => {}
    }
  },
  methods: {
    close() {
      this.$emit('update:visible', false);
      this.onClose();
    }
  }
}
</script>

<style scoped>
.message-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.message-dialog {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 20px;
  width: 90%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.message-dialog.success .message-dialog-icon {
  background-color: #52c41a;
}

.message-dialog.error .message-dialog-icon {
  background-color: #f5222d;
}

.message-dialog.info .message-dialog-icon {
  background-color: #1890ff;
}

.message-dialog-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
}

.message-dialog-icon i {
  color: white;
  font-size: 32px;
  font-style: normal;
  font-weight: bold;
}

.message-dialog-title {
  font-size: 18px;
  margin: 0 0 8px 0;
  color: #333;
}

.message-dialog-message {
  font-size: 14px;
  margin: 0 0 20px 0;
  color: #666;
}

.message-dialog-btn {
  background-color: #1890ff;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.message-dialog-btn:hover {
  background-color: #40a9ff;
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter, .fade-leave-to {
  opacity: 0;
}
</style> 